package com.ruoyi.student.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.ruoyi.student.domain.vo.SxStudentVo;
import com.ruoyi.teacher.domain.SxTeachers;
import com.ruoyi.teacher.mapper.SxTeachersMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.student.mapper.SxStudentMapper;
import com.ruoyi.student.domain.SxStudent;
import com.ruoyi.student.service.ISxStudentService;

/**
 * 学生信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-07
 */
@Service
public class SxStudentServiceImpl implements ISxStudentService 
{
    @Autowired
    private SxStudentMapper sxStudentMapper;

    @Autowired
    private SxTeachersMapper sxTeachersMapper;

    /**
     * 查询学生信息
     * 
     * @param id 学生信息主键
     * @return 学生信息
     */
    @Override
    public SxStudent selectSxStudentById(Long id)
    {
        return sxStudentMapper.selectSxStudentById(id);
    }

    /**
     * 查询学生信息列表
     * 
     * @param sxStudent 学生信息
     * @return 学生信息
     */
    @Override
    public List<SxStudentVo> selectSxStudentList(SxStudent sxStudent)
    {
     List<SxStudent>  sx =   sxStudentMapper.selectSxStudentList(sxStudent);
     List<SxStudentVo>  sxStudentVos =   new ArrayList<>();
        for (SxStudent student : sx) {
            long teacherId = student.getTeacherId();
             SxTeachers sxTeachers = sxTeachersMapper.selectSxTeachersByTeacherId(teacherId);
            SxStudentVo sxStudentVo = new SxStudentVo();
            BeanUtils.copyProperties(student,sxStudentVo);
            sxStudentVo.setTeacherName(sxTeachers.getName());
            sxStudentVos.add(sxStudentVo);
        }
        return sxStudentVos;
    }

    /**
     * 新增学生信息
     * 
     * @param sxStudent 学生信息
     * @return 结果
     */
    @Override
    public int insertSxStudent(SxStudent sxStudent)
    {
        return sxStudentMapper.insertSxStudent(sxStudent);
    }

    /**
     * 修改学生信息
     * 
     * @param sxStudent 学生信息
     * @return 结果
     */
    @Override
    public int updateSxStudent(SxStudent sxStudent)
    {
        return sxStudentMapper.updateSxStudent(sxStudent);
    }

    /**
     * 批量删除学生信息
     * 
     * @param ids 需要删除的学生信息主键
     * @return 结果
     */
    @Override
    public int deleteSxStudentByIds(Long[] ids)
    {
        return sxStudentMapper.deleteSxStudentByIds(ids);
    }

    /**
     * 删除学生信息信息
     * 
     * @param id 学生信息主键
     * @return 结果
     */
    @Override
    public int deleteSxStudentById(Long id)
    {
        return sxStudentMapper.deleteSxStudentById(id);
    }
}
